home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / os2 / cenvi2.arj / DOSOBJ.CMD < prev    next >
OS/2 REXX Batch file  |  1993-12-11  |  7KB  |  185 lines

  1. EXTPROC CEnvi
  2. /****************************************************************
  3.  *** DosObj - This is an example, and a template, for using   ***
  4.  ***          the WinCreateObject function to create any type ***
  5.  ***          of object.  You can easily adapt this.          ***                                       full-screen Windows session.  You may **
  6.  ****************************************************************/
  7.  
  8. #include <PMdll.lib>
  9. //#include <KeyPush.lib>
  10. #include <ClipBrd.lib>
  11. #include <Profile.lib>
  12. SetupString = ""; // initialize to contain nothing
  13.  
  14. // SET THE SESSION PROGRAM TYPE, UNCOMMENT THE FOLLOWING LINE THAT APPLIES
  15.    // Setup("PROGTYPE=FULLSCREEN"); // OS/2 full screen
  16.    // Setup("PROGTYPE=WINDOWABLEVIO");// OS/2 windowed
  17.    // Setup("PROGTYPE=VDM");        // DOS full screen
  18.    Setup("PROGTYPE=WINDOWEDVDM");   // DOS windowed
  19.    // Setup("PROGTYPE=PM");         // PM
  20.    // Setup("PROGTYPE=SEPARATEWIN");// WIN-OS2 window in separate VDM
  21.    // Setup("PROGTYPE=WIN");        // WIN-OS2 full screen
  22.    // Setup("PROGTYPE=WINDOWEDWIN");// WIN-OS2 windowed
  23.    // Setup("PROGTYPE=PROG_31_ENH");   // WIN-OS/2 full screen,
  24.                                        // NOT a separate VDM session
  25.                                        // 3.1 Enhanced
  26.    // Setup("PROGTYPE=PROG_31_ENHSEAMLESSVDM); // WIN-OS2 windowed,
  27.                                                // Separate VDM session
  28.                                                // 3.1 Enhanced
  29.    // Setup("PROGTYPE=PROG_31_ENHSEAMLESSCOMMON); // WIN-OS2 windowed
  30.                                                   // NOT a separate VDM
  31.                                                   // 3.1 Enhanced
  32.  
  33. // Windowed session options; uncomment those to apply
  34.    // Setup("MINIMIZED=YES");    // Start program minimized
  35.    Setup("MAXIMIZED=YES");    // Start program maximized
  36.    // Setup("NOAUTOCLOSE=YES");  // Leaves the window open
  37.    // Setup("NOAUTOCLOSE=NO");   // Closes the window at termination
  38.  
  39. // LOTS OF DOS (and Windows) SETTINGS; USE THOSE THAT ARE NOT THE DEFAULT
  40. // AND THAT YOU WANT TO APPLY, (there's more than listed here)
  41.    // Setup("SET DOS_DEVICE=")
  42.    // Setup("SET DOS_FCBS=2")
  43.    // Setup("SET DOS_FCBS_KEEP=2")
  44.    // Setup("SET DOS_FILES=55")
  45.    // Setup("SET DOS_HIGH=0")
  46.    // Setup("SET DOS_UMB=0")
  47.    // Setup("SET DPMI_DOS_API=ENABLED")
  48.    // Setup("SET DPMI_MEMORY_LIMIT=3")
  49.    // Setup("SET DPMI_NETWORK_BUFF_SIZE=1")
  50.    Setup("SET IDLE_SECONDS=8")
  51.    Setup("SET IDLE_SENSITIVITY=85")
  52.    // Setup("SET EMS_FRAME_LOCATION=NONE")
  53.    // Setup("SET EMS_HIGH_OS_MAP_REGION=0")
  54.    // Setup("SET EMS_LOW_OS_MAP_REGION=0")
  55.    // Setup("SET EMS_MEMORY_LIMIT=0")
  56.    // Setup("SET VIDEO_8514A_XGA_IOTRAP=0")
  57.    // Setup("SET VIDEO_SWITCH_NOTIFICATION=1")
  58.    // Setup("SET XMS_HANDLES=0")
  59.    // Setup("SET XMS_MEMORY_LIMIT=0")
  60.    // Setup("SET XMS_MINIMUM_HMA=0")
  61.  
  62. // TELL TO OPEN IMMEDIATELY (OPEN=SETTINGS would open SETTINGS folder)
  63.    Setup("OPEN=DEFAULT");
  64.  
  65. // Set up executable name, parameters, and startup directory
  66.    Setup("EXENAME=*");
  67.    Setup("PARAMETERS=/K mode 80,25");
  68.    Setup("STARTUPDIR=C:\\OS2");
  69.  
  70. // Set the title for this session
  71.    Title = "DOS Box";
  72.  
  73. // Before calling, save current font and set to the one we want: 10 x 8
  74.    GetCurrentBoxFont(SaveFontHeight,SaveFontWidth);
  75.    SetCurrentBoxFont(10,8);
  76.  
  77. // Call the API function to create an object
  78.    handle = WinCreateObject("WPProgram",Title,SetupString,"<WP_NOWHERE>",
  79.                             CO_REPLACEIFEXISTS);
  80.  
  81. // Restore window font to what it used to be
  82.    SetCurrentBoxFont(SaveFontHeight,SaveFontWidth);
  83.  
  84.    if ( handle == NULL )
  85.       printf("\a\a\aUnable to WinCreateObject() with given settings.\n"), exit(1);
  86.  
  87. // Get the Window handle from its title
  88.    hwnd = GetWindowHandle(Title,SwitchHandle)
  89.  
  90. // call switch.cmd CEnvi function to bring this program to the foreground
  91.    WinSwitchToProgram(SwitchHandle);
  92.  
  93. // Get Dimensions of this window and of the whole screen
  94.    #define HWND_DESKTOP 1
  95.    GetWindowPosition(HWND_DESKTOP,col,row,DesktopWidth,DesktopHeight)
  96.    GetWindowPosition(hwnd,col,row,width,height)
  97.  
  98. // Move this window to where we want it, this could be anywhere...
  99. // In this case center it against the right edge of the screen.
  100.    col = DesktopWidth - width;
  101.    row = (DesktopHeight - height) / 2;
  102. // Some screen positions don't look so good, so adjust to "good" position
  103.    #define GOOD_COL_OFFSET 8
  104.    #define GOOD_ROW_OFFSET 1
  105.    col -= (col - GOOD_COL_OFFSET/2) % GOOD_COL_OFFSET
  106.    row -= (row - GOOD_ROW_OFFSET/2) % GOOD_ROW_OFFSET
  107.    MoveWindow( hwnd, col, row );
  108.  
  109. // Send a "DIR" command to this session via the clipboard
  110.    // ClipCommand = "DIR\r";
  111.    // PutClipboardData(ClipCommand,1+strlen(ClipCommand),CF_TEXT);
  112.    // KeyStroke(VK_ALT), KeyStroke('P');
  113.  
  114. /****************** FUNCTIONS USED BY ABOVE CODE *********************/
  115.  
  116. Setup(format) // This is like printf, but adds to the end of SetupString for
  117.               // each incarnation, plus a ';' to separate fields
  118. {
  119.    va_start(va_list,format);
  120.    str = SetupString + strlen(SetupString);
  121.    vsprintf(str,format,va_list);
  122.    va_end(va_list);
  123.    strcat(SetupString,";");
  124. }
  125.  
  126. GetWindowHandle(WindowName,Switch_Handle)
  127. {
  128.    // will try a number of times, to give it time to get going
  129.    #define  RETRY_COUNT    50
  130.    #define  RETRY_DELAY    100   // milliseconds to wait between retries
  131.    for ( retry = 0; retry < RETRY_COUNT; retry++, suspend(RETRY_DELAY) ) {
  132.       // build list of all window titles
  133.       SwitchList = WinQuerySwitchList(PMInfo().hab);
  134.       for ( i = GetArraySpan(SwitchList); 0 <= i; i-- ) {
  135.          if ( 0 == WinQuerySwitchEntry(SwitchList[i],SwEntry) ) {
  136.             if ( !strcmp(WindowName,SwEntry.title)
  137.               &&  NULL != SwEntry.hwnd ) {
  138.                Switch_Handle = SwitchList[i];
  139.                return(SwEntry.hwnd);
  140.             }
  141.          }
  142.       }
  143.    }
  144.    // if made it here then window not found, so exit
  145.    exit(1);
  146. }
  147.  
  148. MoveWindow(hwnd,col,row)
  149. {
  150.    #define ORD_WIN32SETWINDOWPOS 875
  151.    #define SWP_MOVE              0x0002
  152.    #define SWP_NOADJUST          0x0040
  153.    PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
  154.                  hwnd,0,col,row,0,0,SWP_MOVE | SWP_NOADJUST);
  155. }
  156.  
  157. GetWindowPosition(hwnd,Col,Row,Width,Height)
  158. {
  159.    #define SWP_BLOB_SIZE 9 * 4
  160.    BLObSize(swp,SWP_BLOB_SIZE);
  161.    #define ORD_WIN32QUERYWINDOWPOS  837
  162.    if !DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,hwnd,swp)
  163.       exit(1);
  164.    Height = BLObGet(swp,4,SWORD32);
  165.    Width = BLObGet(swp,8,SWORD32);
  166.    Row = BLObGet(swp,12,SWORD32);
  167.    Col = BLObGet(swp,16,SWORD32);
  168. }
  169.  
  170. GetCurrentBoxFont(height,width)
  171. {
  172.    BLObSize(current,2);
  173.    PrfQueryProfileData(HINI_USERPROFILE,"Shield","~Font Size...",current,2);
  174.    height = BLObGet(current,1,UWORD8);
  175.    width = BLObGet(current,0,UWORD8);
  176. }
  177.  
  178. SetCurrentBoxFont(height,width)
  179. {
  180.    BLObPut(current,0,width,UWORD8);
  181.    BLObPut(current,1,height,UWORD8);
  182.    PrfWriteProfileData(HINI_USERPROFILE,"Shield","~Font Size...",current,2);
  183. }
  184.  
  185.